"""
author:zjsxxzh

"""
import socket
import threading

condition = threading.Condition()
HOST='127.0.0.1'
POST = 1315
list=[]

s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
print('socket creat sucess')
s.bind((HOST,POST))
s.listen(10)
print('port bind sucess,socket server is running')

def NotifyAll(hua):
    for c in list:
        c.send(hua.encode('utf-8'))

def ClientIn(nick,conn):
    while 1:
        temp = conn.recv(1024).decode('utf-8')
        print(nick+' say:'+temp)
        NotifyAll(nick+' say:'+temp)

while 1:
    conn , address= s.accept()
    print(address[0]+':'+str(address[1])+'is join!')
    nick=conn.recv(1024).decode('utf-8')
    print(nick+'is join')
    NotifyAll('welcome'+nick+'join python chat room')
    list.append(conn)
    threading.Thread(target=ClientIn,args=(nick,conn,)).start()
